/**
 * 新版部门人员选择模块，提供人员单选及多选功能
 * 
 * @Date: 2016-9-8
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(['jquery', 'init','fullcalendar','fullcalendar_zh-cn','moment','treeview'], 
	function($,init,fullcalendar,calendarLang,moment,treeview) {

	'use strict';

	//js参数
	var jsParam
	
	var rootid = 'user-select-modal';
	var private_method = {
	
	}
	
	var public_method = {
		
		//初始化函数
		init:function(){
			var _el =$('#'+rootid);
    		
    		if(_el.length==1){
    			_el.modal({
			        keyboard: true
			    })
    		}
    		
    		var _url ='/'+ init.getSite()+'/department/query/getDeptUserStaticTree.action';
			
    		var _param = {
    			url:_url,
    			success:function(data){
    				$('#treeview-selectable').treeview({
    					color: "#428bca",
    					showBorder: false,    					
          				multiSelect:true,
    					levels: 1,
			            data: data,
			            onNodeSelected: function(event, node) {
			            	if(window.console){
			            		console.log('node: ' + node.text + ' selected...')
			            	}
			            	var _el = $('#'+rootid +' #'+node.id);
			            	if(_el.length<=0){
				            	var _html = '<div class="list-group-item" id="'+node.id +'">'+
												node.text +							
											'</div>';
					            var _target=$('#'+rootid + ' #selected-list');
					            if(_target.length==1){
					            	_target.append(_html);
					            }
			            	}
				        },
				        onNodeUnselected: function (event, node) {
				        	var _el = $('#'+rootid +' #'+node.id);
				        	if(_el.length>=1)
				        		_el.remove();
//				            $('#checkable-output').prepend('<p>' + node.text + ' was unchecked</p>');
				        }
			          });
    			}
    			,
    			failure:function(){
    				
    			}
    		}
    		$.ajax(_param)
		}
		,
		//脚本打开页面
		openPage:function(_options){
			var _url = '/'+init.getSite()+'/common/query/getPage.action?code=userSelect';
			
			var _container = $('#user-select-pop')
			
			if(_container.length<=0){
				$('body').append('<div id="user-select-pop"></div>');
			}
			
			_container = $('#user-select-pop')
			_container.load(_url);
		}
	}
	
	
	return public_method;
});